package com.honghe.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.honghe.common.annotation.Log;
import com.honghe.common.core.controller.BaseController;
import com.honghe.common.core.domain.AjaxResult;
import com.honghe.common.enums.BusinessType;
import com.honghe.system.domain.CustomerContactRecord;
import com.honghe.system.service.ICustomerContactRecordService;
import com.honghe.common.utils.poi.ExcelUtil;
import com.honghe.common.core.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.honghe.common.utils.SecurityUtils;
import com.honghe.system.domain.BankCustomerCases;

/**
 * 客户联系记录Controller
 * 
 * @author honghe
 */
@RestController
@RequestMapping("/system/contactrecord")
public class CustomerContactRecordController extends BaseController
{
    private static final Logger logger = LoggerFactory.getLogger(CustomerContactRecordController.class);

    @Autowired
    private ICustomerContactRecordService customerContactRecordService;

    /**
     * 查询客户联系记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:contactrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerContactRecord customerContactRecord)
    {
        startPage();
        List<CustomerContactRecord> list = customerContactRecordService.selectCustomerContactRecordList(customerContactRecord);
        return getDataTable(list);
    }

    /**
     * 根据客户ID获取联系记录列表
     */
    @PreAuthorize("@ss.hasAnyPermi({'system:contactrecord:list','system:contactrecord:add','system:contactrecord:edit'})")
    @GetMapping("/listByCaseId/{caseId}")
    public AjaxResult listByCaseId(@PathVariable("caseId") String caseId)
    {
        logger.info("根据客户ID获取联系记录列表，客户ID：{}", caseId);
        try {
            List<CustomerContactRecord> list = customerContactRecordService.selectCustomerContactRecordByCaseId(caseId);
            logger.info("查询结果条数：{}", list != null ? list.size() : 0);
            return success(list);
        } catch (Exception e) {
            logger.error("查询联系记录出错：", e);
            return error("查询联系记录失败：" + e.getMessage());
        }
    }

    /**
     * 导出客户联系记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:contactrecord:export')")
    @Log(title = "客户联系记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerContactRecord customerContactRecord)
    {
        List<CustomerContactRecord> list = customerContactRecordService.selectCustomerContactRecordList(customerContactRecord);
        ExcelUtil<CustomerContactRecord> util = new ExcelUtil<CustomerContactRecord>(CustomerContactRecord.class);
        return util.exportExcel(list, "客户联系记录数据");
    }

    /**
     * 获取客户联系记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:contactrecord:edit')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(customerContactRecordService.selectCustomerContactRecordByRecordId(recordId));
    }

    /**
     * 新增客户联系记录
     */
    @PreAuthorize("@ss.hasPermi('system:contactrecord:add')")
    @Log(title = "客户联系记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerContactRecord customerContactRecord)
    {
        return toAjax(customerContactRecordService.insertCustomerContactRecord(customerContactRecord));
    }

    /**
     * 修改客户联系记录
     */
    @PreAuthorize("@ss.hasPermi('system:contactrecord:edit')")
    @Log(title = "客户联系记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerContactRecord customerContactRecord)
    {
        return toAjax(customerContactRecordService.updateCustomerContactRecord(customerContactRecord));
    }

    /**
     * 删除客户联系记录
     */
    @PreAuthorize("@ss.hasPermi('system:contactrecord:remove')")
    @Log(title = "客户联系记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(customerContactRecordService.deleteCustomerContactRecordByRecordIds(recordIds));
    }
} 